import { Argument, program } from 'commander';

async function callPlugin(plugin: string, entry: string, options: any) {
    const moduleX = eval("require")(`../plugins/${plugin}/out/${entry}`);
    const mainFunc = moduleX.default;
    if (mainFunc) {
        await mainFunc(options);
    }
}

program
    .name('hgeditor')
    .usage('cmd [options]')
    .version('1.0.0');

program.command('res')
    .addArgument(new Argument('<act>', 'choose actions').choices(['res', 'cfg', 'img', 'check', 'img_size', 'eui_str', 'clean_assets', 'trans_res']))
    .option('-e [path]', 'project path, default by using current env path')
    .option('--ext [...]', 'extra options')
    .action((act, opts) => {
        callPlugin("res_genrator", "resgenrator", { act: act, path: opts.e, extra: opts.ext });
    });

program.parse(process.argv);
